
 <!DOCTYPE HTML>
<html >
<head>
  <meta charset="UTF-8">
  
    <title>聊一种哑铃式编程方式 | Typhoon&#39;s code space</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=no">
    
    <meta name="author" content="typhoon">
    

    
    <meta name="description" content="我们先来看一张图片：">
<meta name="keywords" content="哑铃式编程">
<meta property="og:type" content="article">
<meta property="og:title" content="聊一种哑铃式编程方式">
<meta property="og:url" content="http://scorpioaeolus.oschina.io/2018/08/04/聊一种哑铃式编程方式/index.html">
<meta property="og:site_name" content="Typhoon&#39;s code space">
<meta property="og:description" content="我们先来看一张图片：">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/08/04/聊一种哑铃式编程方式/timg.jpg">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/08/04/聊一种哑铃式编程方式/d1.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/08/04/聊一种哑铃式编程方式/d2.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/08/04/聊一种哑铃式编程方式/d3.png">
<meta property="og:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/08/04/聊一种哑铃式编程方式/d4.png">
<meta property="og:updated_time" content="2018-08-04T06:48:55.106Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="聊一种哑铃式编程方式">
<meta name="twitter:description" content="我们先来看一张图片：">
<meta name="twitter:image" content="http://scorpioaeolus.oschina.io/typhoon/2018/08/04/聊一种哑铃式编程方式/timg.jpg">

    
    <link rel="alternative" href="/atom.xml" title="Typhoon&#39;s code space" type="application/atom+xml">
    
    
    <link rel="icon" href="/typhoon/img/java.png">
    
    
    <link rel="apple-touch-icon" href="/typhoon/img/jacman.jpg">
    <link rel="apple-touch-icon-precomposed" href="/typhoon/img/jacman.jpg">
    
    <link rel="stylesheet" href="/typhoon/css/style.css">
</head>

  <body>
    <header>
      
<div>
		
			<div id="imglogo">
				<a href="/typhoon/"><img src="/typhoon/img/java.png" alt="Typhoon&#39;s code space" title="Typhoon&#39;s code space"/></a>
			</div>
			
			<div id="textlogo">
				<h1 class="site-name"><a href="/typhoon/" title="Typhoon&#39;s code space">Typhoon&#39;s code space</a></h1>
				<h2 class="blog-motto"></h2>
			</div>
			<div class="navbar"><a class="navbutton navmobile" href="#" title="Menu">
			</a></div>
			<nav class="animated">
				<ul>
					<ul>
					 
						<li><a href="/typhoon/">主页</a></li>
					
						<li><a href="/typhoon/archives">归档</a></li>
					
						<li><a href="/typhoon/about">关于</a></li>
					
					<li>
 					
					<form class="search" action="//google.com/search" method="get" accept-charset="utf-8">
						<label>Search</label>
						<input type="search" id="search" name="q" autocomplete="off" maxlength="20" placeholder="Search" />
						<input type="hidden" name="q" value="site:scorpioaeolus.oschina.io">
					</form>
					
					</li>
				</ul>
			</nav>			
</div>
    </header>
    <div id="container">
      <div id="main" class="post" itemscope itemprop="blogPost">
  
	<article itemprop="articleBody"> 
		<header class="article-info clearfix">
  <h1 itemprop="name">
    
      <a href="/typhoon/2018/08/04/聊一种哑铃式编程方式/" title="聊一种哑铃式编程方式" itemprop="url">聊一种哑铃式编程方式</a>
  </h1>
  <p class="article-author">By
       
		<a href="/typhoon/about" title="typhoon" target="_blank" itemprop="author">typhoon</a>
		
  <p class="article-time">
    <time datetime="2018-08-04T02:34:42.000Z" itemprop="datePublished"> Published 2018-08-04</time>
    
  </p>
</header>
	<div class="article-content">
		
		<div id="toc" class="toc-article">
			<strong class="toc-title">Contents</strong>
		
			<ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#一、线性编程以及存在的问题"><span class="toc-number">1.</span> <span class="toc-text">一、线性编程以及存在的问题</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#优点"><span class="toc-number">1.1.</span> <span class="toc-text">优点</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#缺点"><span class="toc-number">1.2.</span> <span class="toc-text">缺点</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#二、“哑铃式”编程实现思想以及解决的问题"><span class="toc-number">2.</span> <span class="toc-text">二、“哑铃式”编程实现思想以及解决的问题</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#优点-1"><span class="toc-number">2.1.</span> <span class="toc-text">优点</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#缺点-1"><span class="toc-number">2.2.</span> <span class="toc-text">缺点</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#三、“哑铃式”编程实例实现"><span class="toc-number">3.</span> <span class="toc-text">三、“哑铃式”编程实例实现</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#总结"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a></li></ol>
		
		</div>
		
		<pre><code>我们先来看一张图片：
</code></pre><a id="more"></a>
<img src="/typhoon/2018/08/04/聊一种哑铃式编程方式/timg.jpg" alt="dumbbell" title="dumbbell">
<pre><code>    健身的朋友都知道哑铃，中间比较细，两头比较重。那么和我们编程有什么关系呢？
先描述一个概念，我们大多数初中级开发人员，都喜欢直线式开发模式，也就是来了一个
需求我就可以完全从头到脚写一套，接下来我们对这种方式存在的问题做详细分析以及给
出一种比较好的解决方案。
</code></pre><h5 id="一、线性编程以及存在的问题"><a href="#一、线性编程以及存在的问题" class="headerlink" title="一、线性编程以及存在的问题"></a>一、线性编程以及存在的问题</h5><pre><code>    所谓线性编程，就是采取简单粗暴的方式，对类似业务的需求都实现一套， 基本实现模式
如下图：
</code></pre><img src="/typhoon/2018/08/04/聊一种哑铃式编程方式/d1.png" alt="dumbbell" title="dumbbell">
<pre><code>    存在即合理，对这种大多数人都喜欢使用的编码方式，肯定有其存在的意义，我们先分析下
其优缺点：
</code></pre><h6 id="优点"><a href="#优点" class="headerlink" title="优点"></a>优点</h6><pre><code>1.上手简单，对程序员能力要求无门槛
2.通俗易懂，从头到尾没有分支逻辑
</code></pre><h6 id="缺点"><a href="#缺点" class="headerlink" title="缺点"></a>缺点</h6><pre><code>1.存在很多逻辑相似的重复代码
2.如果业务发生变化，可能导致所有线路代码变更
3.对于一些非核心逻辑，参数校验、权限校验，每条链路都要写一份重复代码
</code></pre><h5 id="二、“哑铃式”编程实现思想以及解决的问题"><a href="#二、“哑铃式”编程实现思想以及解决的问题" class="headerlink" title="二、“哑铃式”编程实现思想以及解决的问题"></a>二、“哑铃式”编程实现思想以及解决的问题</h5><pre><code>    对于“哑铃式”编程，应该大部分人没有这个概念，或者说已经知道这种编程方式，但是对这个奇怪的
命名不知所措。首先声明一下，“哑铃式”编程是我自己根据实际开发经验总结提炼后的一个命名。我们先
上一张图，针对上一步改造后的图：
</code></pre><img src="/typhoon/2018/08/04/聊一种哑铃式编程方式/d2.png" alt="dumbbell" title="dumbbell">
<pre><code>    这幅图和前边那幅图不一样的地方是，取消了服务层，增加了调配层和执行器层，其核心思想有两点：
1）收口；所有的请求由调度层收拢，便于管控
2）抽象；把一些通用的逻辑抽象到调度层
3）差异性；不同的请求类型有通用的逻辑，但是也有差异性的逻辑

    新加两层的作用：
I)调配层：逻辑收口，抽象通用逻辑，根据不同操作类型调度不同执行器。
II）执行器层：控制器层不直接和外部服务或者本地DB操作打交道，不同操作类型的参数和操作
    权限个性化校验。

    前边分析了“哑铃式”编程的实现思想，我们来分析下其优缺点：
</code></pre><h6 id="优点-1"><a href="#优点-1" class="headerlink" title="优点"></a>优点</h6><pre><code>1.代码结构化程度高
2.插件式编程
3.代码复用度高，冗余度低
</code></pre><h6 id="缺点-1"><a href="#缺点-1" class="headerlink" title="缺点"></a>缺点</h6><pre><code>1.门槛比较高；有大量编程经验基类的开发人员才会有这个意识和思想
2.代码结构和层次复杂度变高
</code></pre><h5 id="三、“哑铃式”编程实例实现"><a href="#三、“哑铃式”编程实例实现" class="headerlink" title="三、“哑铃式”编程实例实现"></a>三、“哑铃式”编程实例实现</h5><pre><code>    上边我们分析了传统线性编程和“哑铃式”编程的优缺点，我们根据具体实例来实现“哑铃式”编程。
假如我们有个用户的增删改查的需求，接下来我们编写代码实现：
</code></pre><img src="/typhoon/2018/08/04/聊一种哑铃式编程方式/d3.png" alt="dumbbell" title="dumbbell">
<pre><code>上图是我们用到的类，其中比较核心的类是：
IOperation
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * 操作接口</div><div class="line"> */</div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">IOperation</span> &lt;<span class="title">T</span>&gt; </span>&#123;</div><div class="line"></div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 具体操作</div><div class="line">     *</div><div class="line">     * <span class="doctag">@param</span> t</div><div class="line">     * <span class="doctag">@throws</span> UserException</div><div class="line">     */</div><div class="line">    <span class="function"><span class="keyword">void</span> <span class="title">operate</span><span class="params">(T t)</span> <span class="keyword">throws</span> UserException</span>;</div><div class="line"></div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>AbstractUserOperation
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> <span class="keyword">abstract</span> <span class="class"><span class="keyword">class</span> <span class="title">AbstractUserOperation</span> <span class="keyword">implements</span> <span class="title">IOperation</span> &lt;<span class="title">UserOptContext</span>&gt; </span>&#123;</div><div class="line"></div><div class="line">    <span class="meta">@Autowired</span></div><div class="line">    <span class="keyword">protected</span> UserDao userDao;</div><div class="line"></div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">operate</span><span class="params">(UserOptContext context)</span> <span class="keyword">throws</span> UserException </span>&#123;</div><div class="line">        checkParameter(context);</div><div class="line">        <span class="keyword">if</span>(hasPermission(context)) &#123;</div><div class="line">            execute(context);</div><div class="line">        &#125; <span class="keyword">else</span> &#123;</div><div class="line">            notPermissionExecute(context);</div><div class="line">        &#125;</div><div class="line"></div><div class="line">    &#125;</div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 校验操作权限和数据权限</div><div class="line">     *</div><div class="line">     * <span class="doctag">@param</span> context</div><div class="line">     * <span class="doctag">@return</span></div><div class="line">     * <span class="doctag">@throws</span> UserException</div><div class="line">     */</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">boolean</span> <span class="title">hasPermission</span><span class="params">(UserOptContext context)</span> <span class="keyword">throws</span> UserException </span>&#123;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">true</span>;</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 具体执行操作，交给子类实现</div><div class="line">     *</div><div class="line">     * <span class="doctag">@param</span> context</div><div class="line">     * <span class="doctag">@throws</span> UserException</div><div class="line">     */</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">void</span> <span class="title">execute</span><span class="params">(UserOptContext context)</span> <span class="keyword">throws</span> UserException</span>;</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 没有权限执行的操作</div><div class="line">     *</div><div class="line">     * <span class="doctag">@param</span> context</div><div class="line">     * <span class="doctag">@throws</span> UserException</div><div class="line">     */</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">notPermissionExecute</span><span class="params">(UserOptContext context)</span> <span class="keyword">throws</span> UserException </span>&#123;</div><div class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> UserException(<span class="string">"没有权限操作"</span>);</div><div class="line">    &#125;</div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 参数校验，交给子类实现差异化</div><div class="line">     *</div><div class="line">     * <span class="doctag">@param</span> context</div><div class="line">     * <span class="doctag">@throws</span> UserException</div><div class="line">     */</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">void</span> <span class="title">checkParameter</span><span class="params">(UserOptContext context)</span> <span class="keyword">throws</span> UserException </span>;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>InsertUserOperation
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * 新增</div><div class="line"> *</div><div class="line"> */</div><div class="line"><span class="meta">@Component</span></div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">InsertUserOperation</span> <span class="keyword">extends</span> <span class="title">AbstractUserOperation</span> </span>&#123;</div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">execute</span><span class="params">(UserOptContext context)</span> <span class="keyword">throws</span> UserException </span>&#123;</div><div class="line">        <span class="keyword">this</span>.userDao.create(context.getName(),context.getSex(),context.getAge());</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">checkParameter</span><span class="params">(UserOptContext context)</span> <span class="keyword">throws</span> UserException </span>&#123;</div><div class="line">        ParameterChecker.checkNotNull(context,<span class="string">"context"</span>);</div><div class="line">        ParameterChecker.checkNotNull(context.getName(),<span class="string">"name"</span>);</div><div class="line">        ParameterChecker.checkNotNull(context.getAge(),<span class="string">"age"</span>);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>DeleteUserOperation
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * 删除</div><div class="line"> *</div><div class="line"> */</div><div class="line"><span class="meta">@Component</span></div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">DeleteUserOperation</span> <span class="keyword">extends</span> <span class="title">AbstractUserOperation</span> </span>&#123;</div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">execute</span><span class="params">(UserOptContext context)</span> <span class="keyword">throws</span> UserException </span>&#123;</div><div class="line">        <span class="keyword">this</span>.userDao.deleteByPk(context.getId());</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">checkParameter</span><span class="params">(UserOptContext context)</span> <span class="keyword">throws</span> UserException </span>&#123;</div><div class="line">        ParameterChecker.checkNotNull(context,<span class="string">"context"</span>);</div><div class="line">        ParameterChecker.checkNotNull(context.getId(),<span class="string">"id"</span>);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>UpdateUserOperation
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * 更新</div><div class="line"> *</div><div class="line"> */</div><div class="line"><span class="meta">@Component</span></div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UpdateUserOperation</span> <span class="keyword">extends</span> <span class="title">AbstractUserOperation</span> </span>&#123;</div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">execute</span><span class="params">(UserOptContext context)</span> <span class="keyword">throws</span> UserException </span>&#123;</div><div class="line">        <span class="keyword">this</span>.userDao.updateByPk(context.getId(),context.getName(),context.getAge());</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">checkParameter</span><span class="params">(UserOptContext context)</span> <span class="keyword">throws</span> UserException </span>&#123;</div><div class="line">        ParameterChecker.checkNotNull(context,<span class="string">"context"</span>);</div><div class="line">        ParameterChecker.checkNotNull(context.getAge(),<span class="string">"id"</span>);</div><div class="line">        ParameterChecker.checkNotNull(context.getName(),<span class="string">"name"</span>);</div><div class="line">        ParameterChecker.checkNotNull(context.getAge(),<span class="string">"age"</span>);</div><div class="line"></div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>调度器UserOptManager
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/**</span></div><div class="line"> * 用户操作调配器</div><div class="line"> */</div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserOptManager</span> </span>&#123;</div><div class="line"></div><div class="line">    <span class="keyword">private</span> Map&lt;UserOptTypeEnum,IOperation&gt; proccessMap = <span class="keyword">new</span> HashMap&lt;&gt;();</div><div class="line"></div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">operate</span><span class="params">(UserOptTypeEnum optTypeEnum,UserOptContext context)</span>   <span class="keyword">throws</span> UserException </span>&#123;</div><div class="line">        IOperation operation = proccessMap.get(optTypeEnum);</div><div class="line">        <span class="keyword">if</span>(<span class="keyword">null</span> == operation) &#123;</div><div class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> UserException(<span class="string">"执行器不存在"</span>);</div><div class="line">        &#125;</div><div class="line">        context.setOperateType(optTypeEnum.getCode());</div><div class="line">        operation.operate(context);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 新增</div><div class="line">     *</div><div class="line">     * <span class="doctag">@param</span> context</div><div class="line">     * <span class="doctag">@throws</span> UserException</div><div class="line">     */</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">insert</span><span class="params">(UserOptContext context)</span> <span class="keyword">throws</span> UserException </span>&#123;</div><div class="line">        <span class="keyword">this</span>.operate(UserOptTypeEnum.INSERT,context);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 删除</div><div class="line">     *</div><div class="line">     * <span class="doctag">@param</span> context</div><div class="line">     * <span class="doctag">@throws</span> UserException</div><div class="line">     */</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">delete</span><span class="params">(UserOptContext context)</span> <span class="keyword">throws</span> UserException </span>&#123;</div><div class="line">        <span class="keyword">this</span>.operate(UserOptTypeEnum.DELETE,context);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="comment">/**</span></div><div class="line">     * 更新</div><div class="line">     * <span class="doctag">@param</span> context</div><div class="line">     * <span class="doctag">@throws</span> UserException</div><div class="line">     */</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">update</span><span class="params">(UserOptContext context)</span> <span class="keyword">throws</span> UserException </span>&#123;</div><div class="line">        <span class="keyword">this</span>.operate(UserOptTypeEnum.UPDATE,context);</div><div class="line">    &#125;</div><div class="line"></div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">setProccessMap</span><span class="params">(Map&lt;UserOptTypeEnum, IOperation&gt; proccessMap)</span> </span>&#123;</div><div class="line">        <span class="keyword">this</span>.proccessMap = proccessMap;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>还有bean配置文件
</code></pre><figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">&lt;bean id="userOptManager" class="com.typhoon.spring_boot_demo1.manager.UserOptManager"&gt;</div><div class="line">    &lt;property name="proccessMap"&gt;</div><div class="line">        &lt;map&gt;</div><div class="line">            &lt;entry key="INSERT" value-ref="insertUserOperation"/&gt;</div><div class="line">            &lt;entry key="DELETE" value-ref="deleteUserOperation"/&gt;</div><div class="line">            &lt;entry key="UPDATE" value-ref="updateUserOperation"/&gt;</div><div class="line">        &lt;/map&gt;</div><div class="line">    &lt;/property&gt;</div><div class="line">&lt;/bean&gt;</div></pre></td></tr></table></figure>
<pre><code>控制器层写了三个测试方法：
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@RequestMapping</span>(<span class="string">"/user/insert"</span>)</div><div class="line">	<span class="function"><span class="keyword">public</span> Map&lt;String,Object&gt; <span class="title">saveUser</span><span class="params">(HttpServletRequest request,</span></span></div><div class="line">									   HttpServletResponse response,</div><div class="line">									   @RequestParam(<span class="string">"name"</span>) String name,</div><div class="line">									   @<span class="title">RequestParam</span><span class="params">(<span class="string">"sex"</span>)</span> Integer sex,</div><div class="line">									   @<span class="title">RequestParam</span><span class="params">(<span class="string">"age"</span>)</span> Integer age) &#123;</div><div class="line">		Map&lt;String,Object&gt; result = <span class="keyword">new</span> HashMap&lt;&gt;();</div><div class="line">		<span class="keyword">if</span>(idParamIllegal(name,age,sex)) &#123;</div><div class="line">			result.put(<span class="string">"success"</span>,<span class="keyword">false</span>);</div><div class="line">			result.put(<span class="string">"msg"</span>,<span class="string">"参数非法"</span>);</div><div class="line">			<span class="keyword">return</span> result;</div><div class="line">		&#125;</div><div class="line">		<span class="keyword">try</span> &#123;</div><div class="line">			UserOptContext  context = <span class="keyword">new</span> UserOptContext();</div><div class="line">			context.setName(name);</div><div class="line">			context.setAge(age);</div><div class="line">			context.setSex(sex);</div><div class="line">			<span class="keyword">this</span>.userOptManager.insert(context);</div><div class="line">			result.put(<span class="string">"success"</span>,<span class="keyword">true</span>);</div><div class="line">			result.put(<span class="string">"msg"</span>,<span class="string">"新增成功"</span>);</div><div class="line">			<span class="keyword">return</span> result;</div><div class="line">		&#125; <span class="keyword">catch</span> (Exception e) &#123;</div><div class="line">			e.printStackTrace();</div><div class="line">			result.put(<span class="string">"success"</span>,<span class="keyword">false</span>);</div><div class="line">			result.put(<span class="string">"msg"</span>,<span class="string">"新增操作异常"</span>);</div><div class="line">		&#125;</div><div class="line">		<span class="keyword">return</span> result;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	<span class="meta">@RequestMapping</span>(<span class="string">"/user/delete"</span>)</div><div class="line">	<span class="function"><span class="keyword">public</span> Map&lt;String,Object&gt; <span class="title">deleteUser</span><span class="params">(HttpServletRequest request,</span></span></div><div class="line">									   HttpServletResponse response,</div><div class="line">									   @RequestParam(<span class="string">"id"</span>) Long id) &#123;</div><div class="line">		Map&lt;String,Object&gt; result = <span class="keyword">new</span> HashMap&lt;&gt;();</div><div class="line">		<span class="keyword">if</span>(idParamIllegal(id)) &#123;</div><div class="line">			result.put(<span class="string">"success"</span>,<span class="keyword">false</span>);</div><div class="line">			result.put(<span class="string">"msg"</span>,<span class="string">"参数非法"</span>);</div><div class="line">			<span class="keyword">return</span> result;</div><div class="line">		&#125;</div><div class="line">		<span class="keyword">try</span> &#123;</div><div class="line">			UserOptContext  context = <span class="keyword">new</span> UserOptContext();</div><div class="line">			context.setId(id);</div><div class="line">			<span class="keyword">this</span>.userOptManager.delete(context);</div><div class="line">			result.put(<span class="string">"success"</span>,<span class="keyword">true</span>);</div><div class="line">			result.put(<span class="string">"msg"</span>,<span class="string">"删除成功"</span>);</div><div class="line">			<span class="keyword">return</span> result;</div><div class="line">		&#125; <span class="keyword">catch</span> (Exception e) &#123;</div><div class="line">			e.printStackTrace();</div><div class="line">			result.put(<span class="string">"success"</span>,<span class="keyword">false</span>);</div><div class="line">			result.put(<span class="string">"msg"</span>,<span class="string">"删除操作异常"</span>);</div><div class="line">		&#125;</div><div class="line">		<span class="keyword">return</span> result;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	<span class="meta">@RequestMapping</span>(<span class="string">"/user/update"</span>)</div><div class="line">	<span class="function"><span class="keyword">public</span> Map&lt;String,Object&gt; <span class="title">updateUser</span><span class="params">(HttpServletRequest request,</span></span></div><div class="line">										 HttpServletResponse response,</div><div class="line">										 @RequestParam(<span class="string">"id"</span>) Long id,</div><div class="line">										 @<span class="title">RequestParam</span><span class="params">(<span class="string">"name"</span>)</span> String name,</div><div class="line">										 @<span class="title">RequestParam</span><span class="params">(<span class="string">"sex"</span>)</span> Integer sex,</div><div class="line">										 @<span class="title">RequestParam</span><span class="params">(<span class="string">"age"</span>)</span> Integer age</div><div class="line">										 ) &#123;</div><div class="line">		Map&lt;String,Object&gt; result = <span class="keyword">new</span> HashMap&lt;&gt;();</div><div class="line">		<span class="keyword">if</span>(idParamIllegal(id,name,age,sex)) &#123;</div><div class="line">			result.put(<span class="string">"success"</span>,<span class="keyword">false</span>);</div><div class="line">			result.put(<span class="string">"msg"</span>,<span class="string">"参数非法"</span>);</div><div class="line">			<span class="keyword">return</span> result;</div><div class="line">		&#125;</div><div class="line">		<span class="keyword">try</span> &#123;</div><div class="line">			UserOptContext  context = <span class="keyword">new</span> UserOptContext();</div><div class="line">			context.setId(id);</div><div class="line">			context.setName(name);</div><div class="line">			context.setAge(age);</div><div class="line">			context.setSex(sex);</div><div class="line">			<span class="keyword">this</span>.userOptManager.update(context);</div><div class="line">			result.put(<span class="string">"success"</span>,<span class="keyword">true</span>);</div><div class="line">			result.put(<span class="string">"msg"</span>,<span class="string">"更新成功"</span>);</div><div class="line">			<span class="keyword">return</span> result;</div><div class="line">		&#125; <span class="keyword">catch</span> (Exception e) &#123;</div><div class="line">			e.printStackTrace();</div><div class="line">			result.put(<span class="string">"success"</span>,<span class="keyword">false</span>);</div><div class="line">			result.put(<span class="string">"msg"</span>,<span class="string">"更新操作异常"</span>);</div><div class="line">		&#125;</div><div class="line">		<span class="keyword">return</span> result;</div><div class="line">	&#125;</div><div class="line"></div><div class="line">	<span class="comment">/**</span></div><div class="line">	 * 检查参数是否非法</div><div class="line">	 * <span class="doctag">@param</span> params</div><div class="line">	 * <span class="doctag">@return</span></div><div class="line">	 */</div><div class="line">	<span class="function"><span class="keyword">private</span> <span class="keyword">boolean</span> <span class="title">idParamIllegal</span><span class="params">(Object ... params)</span> </span>&#123;</div><div class="line">		<span class="keyword">for</span>(Object obj : params) &#123;</div><div class="line">			<span class="keyword">if</span>(<span class="keyword">null</span> == obj) &#123;</div><div class="line">				<span class="keyword">return</span> <span class="keyword">true</span>;</div><div class="line">			&#125;</div><div class="line">		&#125;</div><div class="line">		<span class="keyword">return</span> <span class="keyword">false</span>;</div><div class="line">	&#125;</div></pre></td></tr></table></figure>
<pre><code>启动器：
</code></pre><figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="meta">@SpringBootApplication</span></div><div class="line"><span class="meta">@ImportResource</span>(<span class="string">"classpath:user-opt.xml"</span>)</div><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">App</span> </span></div><div class="line">&#123;</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">( String[] args )</span></span></div><div class="line">    &#123;</div><div class="line">        SpringApplication.run(App.class, args);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<pre><code>    项目启动后，对用户的增删改操作都没有问题，有兴趣的可以自己把代码拉下来跑一下。
对于上面的代码实现，我整理了一张图：
</code></pre><img src="/typhoon/2018/08/04/聊一种哑铃式编程方式/d4.png" alt="dumbbell" title="dumbbell">
<pre><code>   从图中我们可以很清晰的看出，请求到UserOptManager被收住，然后到底层业务逻辑又扩散，也就是先粗
后细，然后再变粗，特别像平时健身用的哑铃。
</code></pre><h5 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h5><pre><code>    通过上述一系列描述，我们对“哑铃式”编程做了很详细的介绍，并且用代码实现了这种编程模式，其实我想表达的核心思想是，
在日常开发过程中要学会业务归类和逻辑抽象，该做成通用逻辑的时候就抽出来，该使用个性化逻辑的时候就表现出差异化，希望
在日常开发和学习中对大家有帮助。
</code></pre>  
	</div>
		<footer class="article-footer clearfix">
<div class="article-catetags">

<div class="article-categories">
  <span></span>
  <a class="article-category-link" href="/typhoon/categories/案例分析/">案例分析</a>
</div>


  <div class="article-tags">
  
  <span></span> <a href="/typhoon/tags/哑铃式编程/">哑铃式编程</a>
  </div>

</div>



	<div class="article-share" id="share">
	
	  <div data-url="http://scorpioaeolus.oschina.io/2018/08/04/聊一种哑铃式编程方式/" data-title="聊一种哑铃式编程方式 | Typhoon&#39;s code space" data-tsina="null" class="share clearfix">
	  </div>
	
	</div>


</footer>

   	       
	</article>
	
<nav class="article-nav clearfix">
 
 <div class="prev" >
 <a href="/typhoon/2018/08/11/Collections工具类二分查找优化/" title="jdk源码分析之Collections--二分查找优化">
  <strong>上一篇：</strong><br/>
  <span>
  jdk源码分析之Collections--二分查找优化</span>
</a>
</div>


<div class="next">
<a href="/typhoon/2018/07/22/聊一聊基于业务场景的重试及实现/"  title="聊一聊基于业务场景的重试及实现">
 <strong>下一篇：</strong><br/> 
 <span>聊一聊基于业务场景的重试及实现
</span>
</a>
</div>

</nav>

	


</div>  
      <div class="openaside"><a class="navbutton" href="#" title="Show Sidebar"></a></div>

  <div id="toc" class="toc-aside">
  <strong class="toc-title">Contents</strong>
 
 <ol class="toc"><li class="toc-item toc-level-5"><a class="toc-link" href="#一、线性编程以及存在的问题"><span class="toc-number">1.</span> <span class="toc-text">一、线性编程以及存在的问题</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#优点"><span class="toc-number">1.1.</span> <span class="toc-text">优点</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#缺点"><span class="toc-number">1.2.</span> <span class="toc-text">缺点</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#二、“哑铃式”编程实现思想以及解决的问题"><span class="toc-number">2.</span> <span class="toc-text">二、“哑铃式”编程实现思想以及解决的问题</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#优点-1"><span class="toc-number">2.1.</span> <span class="toc-text">优点</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#缺点-1"><span class="toc-number">2.2.</span> <span class="toc-text">缺点</span></a></li></ol></li><li class="toc-item toc-level-5"><a class="toc-link" href="#三、“哑铃式”编程实例实现"><span class="toc-number">3.</span> <span class="toc-text">三、“哑铃式”编程实例实现</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#总结"><span class="toc-number">4.</span> <span class="toc-text">总结</span></a></li></ol>
 
  </div>

<div id="asidepart">
<div class="closeaside"><a class="closebutton" href="#" title="Hide Sidebar"></a></div>
<aside class="clearfix">

  


  
<div class="categorieslist">
	<p class="asidetitle">Categories</p>
		<ul>
		
		  
			<li><a href="/typhoon/categories/dubbo/" title="dubbo">dubbo<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java性能优化/" title="java性能优化">java性能优化<sup>17</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/java源码分析/" title="java源码分析">java源码分析<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/motan/" title="motan">motan<sup>2</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/spring/" title="spring">spring<sup>11</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springboot/" title="springboot">springboot<sup>28</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/springmvc/" title="springmvc">springmvc<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/容器/" title="容器">容器<sup>1</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/工具/" title="工具">工具<sup>7</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/性能优化/" title="性能优化">性能优化<sup>5</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/架构/" title="架构">架构<sup>8</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/案例分析/" title="案例分析">案例分析<sup>13</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/缓存/" title="缓存">缓存<sup>4</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
		  
		
		  
			<li><a href="/typhoon/categories/面试题/" title="面试题">面试题<sup>1</sup></a></li>
		  
		
		</ul>
</div>


  
<div class="tagslist">
	<p class="asidetitle">Tags</p>
		<ul class="clearfix">
		
			
				<li><a href="/typhoon/tags/springboot/" title="springboot">springboot<sup>28</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/java性能优化/" title="java性能优化">java性能优化<sup>9</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/限流/" title="限流">限流<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring5/" title="Spring5">Spring5<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/设计模式/" title="设计模式">设计模式<sup>3</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/案例分析/" title="案例分析">案例分析<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/性能优化/" title="性能优化">性能优化<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/Spring/" title="Spring">Spring<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo/" title="dubbo">dubbo<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/分页/" title="分页">分页<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/并发/" title="并发">并发<sup>2</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/异常拦截/" title="异常拦截">异常拦截<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo分布式事务/" title="dubbo分布式事务">dubbo分布式事务<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/自带图片/" title="自带图片">自带图片<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/svn导出mvn项目/" title="svn导出mvn项目">svn导出mvn项目<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/dubbo过滤器/" title="dubbo过滤器">dubbo过滤器<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/排序性能对比/" title="排序性能对比">排序性能对比<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/ListenableFuture/" title="ListenableFuture">ListenableFuture<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/PropertyChangeListener/" title="PropertyChangeListener">PropertyChangeListener<sup>1</sup></a></li>
			
		
			
				<li><a href="/typhoon/tags/jdbcTemplate高可用/" title="jdbcTemplate高可用">jdbcTemplate高可用<sup>1</sup></a></li>
			
		
		</ul>
</div>


  <div class="linkslist">
  <p class="asidetitle">Links</p>
    <ul>
        
          <li>
            
            	<a href="https://coderq.com" target="_blank" title="一个面向程序员交流分享的新一代社区">码农圈</a>
            
          </li>
        
          <li>
            
            	<a href="http://wuchong.me" target="_blank" title="Jark&#39;s Blog">Jark&#39;s Blog</a>
            
          </li>
        
    </ul>
</div>

  


  <div class="rsspart">
	<a href="/atom.xml" target="_blank" title="rss">RSS</a>
</div>

  <div class="weiboshow">
  <p class="asidetitle">Weibo</p>
    <iframe width="100%" height="119" class="share_self"  frameborder="0" scrolling="no" src="http://widget.weibo.com/weiboshow/index.php?language=&width=0&height=119&fansRow=2&ptype=1&speed=0&skin=9&isTitle=1&noborder=1&isWeibo=0&isFans=0&uid=null&verifier=b3593ceb&dpc=1"></iframe>
</div>


</aside>
</div>
    </div>
    <footer><div id="footer" >
	
	<div class="line">
		<span></span>
		<div class="author"></div>
	</div>
	
	
	<section class="info">
		<p> Hello ,I&#39;m a java coder. <br/>
			This is my blog,believe it or not.</p>
	</section>
	 
	<div class="social-font" class="clearfix">
		
		
		
		
		
		
		
		
		
		
		<a href="mailto:ScorpioAeolus@163.com" target="_blank" class="icon-email" title="Email Me"></a>
		
	</div>
			
		

		<p class="copyright">
		Powered by <a href="http://hexo.io" target="_blank" title="hexo">hexo</a> and Theme by <a href="https://github.com/wuchong/jacman" target="_blank" title="Jacman">Jacman</a> © 2019 
		
		<a href="/typhoon/about" target="_blank" title="typhoon">typhoon</a>
		
		
		</p>
</div>
</footer>
    <script src="/typhoon/js/jquery-2.0.3.min.js"></script>
<script src="/typhoon/js/jquery.imagesloaded.min.js"></script>
<script src="/typhoon/js/gallery.js"></script>
<script src="/typhoon/js/jquery.qrcode-0.12.0.min.js"></script>

<script type="text/javascript">
$(document).ready(function(){ 
  $('.navbar').click(function(){
    $('header nav').toggleClass('shownav');
  });
  var myWidth = 0;
  function getSize(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
  };
  var m = $('#main'),
      a = $('#asidepart'),
      c = $('.closeaside'),
      o = $('.openaside');
  c.click(function(){
    a.addClass('fadeOut').css('display', 'none');
    o.css('display', 'block').addClass('fadeIn');
    m.addClass('moveMain');
  });
  o.click(function(){
    o.css('display', 'none').removeClass('beforeFadeIn');
    a.css('display', 'block').removeClass('fadeOut').addClass('fadeIn');      
    m.removeClass('moveMain');
  });
  $(window).scroll(function(){
    o.css("top",Math.max(80,260-$(this).scrollTop()));
  });
  
  $(window).resize(function(){
    getSize(); 
    if (myWidth >= 1024) {
      $('header nav').removeClass('shownav');
    }else{
      m.removeClass('moveMain');
      a.css('display', 'block').removeClass('fadeOut');
      o.css('display', 'none');
      
      $('#toc.toc-aside').css('display', 'none');
        
    }
  });
});
</script>

<script type="text/javascript">
$(document).ready(function(){ 
  var ai = $('.article-content>iframe'),
      ae = $('.article-content>embed'),
      t  = $('#toc'),
      ta = $('#toc.toc-aside'),
      o  = $('.openaside'),
      c  = $('.closeaside');
  if(ai.length>0){
    ai.wrap('<div class="video-container" />');
  };
  if(ae.length>0){
   ae.wrap('<div class="video-container" />');
  };
  c.click(function(){
    ta.css('display', 'block').addClass('fadeIn');
  });
  o.click(function(){
    ta.css('display', 'none');
  });
  $(window).scroll(function(){
    ta.css("top",Math.max(140,320-$(this).scrollTop()));
  });
});
</script>


<script type="text/javascript">
$(document).ready(function(){ 
  var $this = $('.share'),
      url = $this.attr('data-url'),
      encodedUrl = encodeURIComponent(url),
      title = $this.attr('data-title'),
      tsina = $this.attr('data-tsina'),
      description = $this.attr('description');
  var html = [
  '<div class="hoverqrcode clearfix"></div>',
  '<a class="overlay" id="qrcode"></a>',
  '<a href="https://www.facebook.com/sharer.php?u=' + encodedUrl + '" class="article-share-facebook" target="_blank" title="Facebook"></a>',
  '<a href="https://twitter.com/intent/tweet?url=' + encodedUrl + '" class="article-share-twitter" target="_blank" title="Twitter"></a>',
  '<a href="#qrcode" class="article-share-qrcode" title="微信"></a>',
  '<a href="http://widget.renren.com/dialog/share?resourceUrl=' + encodedUrl + '&srcUrl=' + encodedUrl + '&title=' + title +'" class="article-share-renren" target="_blank" title="人人"></a>',
  '<a href="http://service.weibo.com/share/share.php?title='+title+'&url='+encodedUrl +'&ralateUid='+ tsina +'&searchPic=true&style=number' +'" class="article-share-weibo" target="_blank" title="微博"></a>',
  '<span title="Share to"></span>'
  ].join('');
  $this.append(html);

  $('.hoverqrcode').hide();

  var myWidth = 0;
  function updatehoverqrcode(){
    if( typeof( window.innerWidth ) == 'number' ) {
      myWidth = window.innerWidth;
    } else if( document.documentElement && document.documentElement.clientWidth) {
      myWidth = document.documentElement.clientWidth;
    };
    var qrsize = myWidth > 1024 ? 200:100;
    var options = {render: 'image', size: qrsize, fill: '#2ca6cb', text: url, radius: 0.5, quiet: 1};
    var p = $('.article-share-qrcode').position();
    $('.hoverqrcode').empty().css('width', qrsize).css('height', qrsize)
                          .css('left', p.left-qrsize/2+20).css('top', p.top-qrsize-10)
                          .qrcode(options);
  };
  $(window).resize(function(){
    $('.hoverqrcode').hide();
  });
  $('.article-share-qrcode').click(function(){
    updatehoverqrcode();
    $('.hoverqrcode').toggle();
  });
  $('.article-share-qrcode').hover(function(){}, function(){
      $('.hoverqrcode').hide();
  });
});   
</script>









<link rel="stylesheet" href="/typhoon/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/typhoon/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 
  $('.article-content').each(function(i){
    $(this).find('img').each(function(){
      if ($(this).parent().hasClass('fancybox')) return;
      var alt = this.alt;
      if (alt) $(this).after('<span class="caption">' + alt + '</span>');
      $(this).wrap('<a href="' + this.src + '" title="' + alt + '" class="fancybox"></a>');
    });
    $(this).find('.fancybox').each(function(){
      $(this).attr('rel', 'article' + i);
    });
  });
  if($.fancybox){
    $('.fancybox').fancybox();
  }
}); 
</script>



<!-- Analytics Begin -->



<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?e6d1f421bbc9962127a50488f9ed37d1";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>



<!-- Analytics End -->

<!-- Totop Begin -->

	<div id="totop">
	<a title="Back to Top"><img src="/typhoon/img/scrollup.png"/></a>
	</div>
	<script src="/typhoon/js/totop.js"></script>

<!-- Totop End -->

<!-- MathJax Begin -->
<!-- mathjax config similar to math.stackexchange -->


<!-- MathJax End -->

<!-- Tiny_search Begin -->

<!-- Tiny_search End -->

  </body>
</html>
